const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navH: app.data.navHeight,
    usageRecord:[],
    current_page:1,
    last_page:2,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (app.data.jsonPage) {
      var nvabarData = {
        title:'明细',
        bgclase: false,
        showCapsule: true,
        textclase: false,
        texttype: false
      };
      this.setData({
        nvabarData: nvabarData,
      });
    } else {
      var left = this;
      app.getjsonPage = res => {
        var nvabarData = {
          title: '明细',
          bgclase: false,
          showCapsule: true,
          textclase: false,
          texttype: false
        };
        left.setData({
          nvabarData: nvabarData,
        });
      };
    }
    console.log(options)
    this.mymember(options.id)
    this.getUsageRecord(options.date)
  },
  mymember(id) {
    wx.$.fetch('/api/member/card/info/' + id, {
      hideLoading: false,
      method: 'get'
    }).then(res => {
      this.setData({
        cardDeta:res.data.data
      })
    })
  },
  getUsageRecord(day){
    wx.$.fetch('/api/member/card/details/day', {
        method: 'get',
        data:{
          day: day
        }
      }).then(res => {
        console.log(res)
        let data = res.data.data;
        data.map(rest=>{
          let created_at = rest.created_at.split(' ')[0].split('-');
          console.log(created_at)
          rest.created_ats = { year: created_at[0], month: created_at[1] + '.' + created_at[2], Time: rest.created_at.split(' ')[1]}
          return rest
        })
        let usageRecord = this.data.usageRecord.concat(data)
        console.log(usageRecord)
        this.setData({
          usageRecord:usageRecord 
        })
      })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    if (this.data.last_page > this.data.current_page){
      this.data.current_page = this.data.current_page+1;
      this.getUsageRecord(false)
    }else{
       
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})